{extend name="platform/base" /}
{block name="resources"/}
<style>
.modal-infp-style{width:100%;margin:10px auto;}
.modal-infp-style table{width:100%;}
.modal-infp-style table tr td{border: 1px solid #e5e5e5;padding: 10px;}
.ns-main{margin-top: 0;}
.img-container{  display: table-cell;vertical-align: middle;  height: 90px;line-height: 90px; width: 90px;text-align: center;margin-left: 0 !important;}
.img-container img,.img-mid  img{display: inline-block !important;vertical-align: middle !important;max-width: 100% !important;max-height: 100% !important;height: auto !important;width:auto !important;}

.fa {display: grid;}
.text-active, .active>.text {display: none;}
.searchable-select-item.selected ,.searchable-select-item.hover {background: #65bd77 !important;}
.searchable-select{line-height: 1.2!important; border-color: #d9d9d9 !important;}
.searchable-select-dropdown{border: 1px solid #d9d9d9 !important;}
.searchable-select-holder{
	border: 1px solid #d9d9d9 !important;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0) !important;
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0) !important;
    -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
.searchable-select-holder{border-radius: 2px!important;}

</style>

{/block}
 {block name="main"}
<div class="row padder-v">
	<div class="col-sm-9">
	<a href="javascript:;" class="btn btn-sm btn-primary" onclick="batchDelete();" ><i class="fa"></i> 批量删除</a>
	<a href="{:__URL('PLATFORM_MAIN/promotion/addTopic')}" class="btn btn-sm btn-primary"  ><i class="fa"></i> 添加专题活动</a></div>
	<div class="col-sm-2">
		<div class="input-group">
			<input type="text" class="input-sm form-control" id="search_text"
				placeholder="请输入专题活动名称">
		</div>
	</div>
	<div class="col-sm-1">
		<div class="input-group">
			<span class="input-group-btn">
				<button class="btn btn-sm btn-default"  id="search_text" type="button"
					onclick="LoadingInfo(1)">搜索</button>
			</span>
		</div>
	</div>
</div>
<section class="panel panel-default">
	<div class="table-responsive">
		<table class="table table-striped b-light text-sm">
			<colgroup>
				<col style="width: 2%;">
				<col style="width: 25%;">
				<col style="width: 29%;">
				<col style="width: 8%;">
				<col style="width: 20%;">
				<col style="width: 16%;">
			</colgroup>
			<thead>
				<tr>
					<th><i class="checkbox-common"><input type="checkbox" onclick="CheckAll(this)"></i></th>
					<th align="left">活动名称</th>
					<th align="left">图像</th>
					<th align="left">活动状态</th>
					<th align="left">有效时间</th>
					<th align="left">操作</th>
				</tr>
			</thead>
			<tbody id="list">
				
			</tbody>
		</table>
	</div>
	
<div class="modal fade" id="topicInfo" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3 class="modal-title" id="myModaltype">专题活动详情</h3>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table>
						<tr  id="superiorRegionTr">
							<td style="width:60px;">活动名称</td>
							<td colspan='3' id="topic_name" style="margin-bottom: 5px;"></td>
						</tr>
						<tr>
							<td style="width:60px;">关键字</td>
							<td colspan='3' id="keyword"></td>
						</tr>
						<tr>
							<td style="width:60px;">描述</td>
							<td colspan='3' id="desc"></td>
						</tr>
						<tr>
							<td style="width:60px;">图像</td>
							<td colspan='3' style="margin: 6px 0 10px;"><a class="img-mid" href="javascript:;"><img src="" alt=""  id="picture_img" class="topic_img"></a></td>
						</tr>
						<tr>
							<td style="width:60px;">条幅</td>
							<td colspan='3' style="margin: 6px 0 10px;"><a class="img-mid href="javascript:;"><img src="" alt=""  id="scroll_img" class="topic_img"></a></td>
						</tr>
						<tr>
							<td style="width:60px;">背景图</td>
							<td colspan='3' style="margin: 6px 0 10px;"><a class="img-mid" href="javascript:;"><img src="" alt=""  id="background_img" class="topic_img"></a></td>
						</tr>
						<tr>
							<td>有效期</td>
							<td colspan='3' id="time"></td>
						</tr>
						<tr>
							<td>活动状态</td>
							<td colspan='3' id="status"></td>
						</tr>
						<tr>
							<td colspan='3'>商品列表</td>
						</tr>
						<tr id="goods_list"></tr>
					</table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
	{include file="platform/page" /}
</section>
{/block} 
{block name="script"}
<link rel="stylesheet" type="text/css" href="__ROOT__/public/admin/css/plugin/jquery.searchableSelect.css">
<script src="__ROOT__/public/admin/js/plugin/jquery.searchableSelect.js"></script>
<script src="__STATIC__/js/BootstrapMenu.min.js"></script>


<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.common.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/zh-cn.js"></script>
<script type="text/javascript">
$(function(){
	LoadingInfo(1);
});
function LoadingInfo(pageIndex) {
	
	var shop_id = $("#shop_id").val();
	var search_text =$("#search_text").val();
	var state = $("#shop_type").val();
	$.ajax({
		type : "post",
		url : "{:__URL('PLATFORM_MAIN/promotion/TopicList')}",
		async : true,
		data : {
			"pageindex" : pageIndex, 
     		"search_text" : search_text, 
	 		"status" : {$status}
		},
		success : function(data) {
			var html = '';
			$("#total_count_num").text(data["total_count"]);
			$("#page_count_num").text(data["page_count"]);
			$("#page_count").val(data["page_count"]);
			$("#pageNumber a").remove();
			if (data["data"].length > 0) {
				$(".table tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					switch(data['data'][i]['status']){
					case 0:
						var status_name = '未发布';
						break;
					case 1:
						var status_name = '进行中';
						break;
					case 3:
						var status_name = '关闭';
						break;
					case 4:
						var status_name = '结束';
						break;
					}
					html += '<tr align="center">';
					html += '<td  align="left"><div class="cell">';
					if(data['data'][i]['status'] == 1){
						html += '<i class="checkbox-common disabled"><input name="sub_use" type="checkbox" value="'+data["data"][i]["topic_id"]+'" disabled></i>';
					}else{
						html += '<i class="checkbox-common"><input name="sub_no_use" type="checkbox"  value="'+data["data"][i]["topic_id"]+'"></i>';
					}
					html += '<td align="left">' + data["data"][i]["topic_name"] + '</td>';;
					html += '<td  align="left"><div class="img-container" ><img src="'+__IMG(data["data"][i]["picture_img"])+'" alt="" class="topic_img" /></div></td>';
					
					html += '<td align="left">'+ status_name +'</td>';
					html += '<td align="left">开始时间：' + timeStampTurnTime(data["data"][i]["start_time"]) + '<br/>结束时间：' + timeStampTurnTime(data["data"][i]["end_time"]) + '</td>';
					html += '<td align="left">';
					html += '<a target="_blank" href="'+__URL('SHOP_MAIN/goods/promotionTopicGoods?topic_id='+data["data"][i]["topic_id"])+'">预览</a>&nbsp';
					html += '<a href="'+__URL('PLATFORM_MAIN/promotion/updateTopic?topic_id=' + data["data"][i]["topic_id"])+'">编辑</a>&nbsp;';
					html += '<a href="javascript:void(0);"onclick="topicInfo('+data["data"][i]["topic_id"]+')">详情</a>&nbsp;';
					if(data['data'][i]['status'] == 0){
						
						html += '<a href="javascript:void(0);"onclick="delTopic('+data["data"][i]["topic_id"]+')">删除</a>&nbsp;';
						
					}else if(data['data'][i]['status'] == 1){
					
						html += '<a href="javascript:void(0);"onclick="closeTopic('+data["data"][i]["topic_id"]+')">关闭</a>&nbsp;';
						
					}else if(data['data'][i]['status'] == 3){
						
						html += '<a href="javascript:void(0);"onclick="delTopic('+data["data"][i]["topic_id"]+')">删除</a>&nbsp;';
					
					}else if(data['data'][i]['status'] == 4){
						
						html += '<a href="javascript:void(0);"onclick="delTopic('+data["data"][i]["topic_id"]+')">删除</a>&nbsp;';
					
					}
					
					
					html += '</td>';
					html += '</tr>';
					$(".table tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="6">暂无符合条件的数据记录</td></tr>';
				$(".table tbody").html(html);
			}
			$("#list").html(html);
			var totalpage = $("#page_count").val();
			if (totalpage == 1) {
				changeClass("all");
			}
			var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
			$("#pageNumber").append($html);
			img_lazyload();
		}
	});
}


function searchData(){
	LoadingInfo(1);
}

//删除限时折扣
function delTopic(topic_id){
	$.ajax({
		type:"post",
		url : "{:__URL('PLATFORM_MAIN/promotion/delTopic')}",
		data : { "topic_id" : topic_id.toString() },
		dataType : "json",
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/promotion/topicList')}");
			}else if(data["code"] == -1){
				showMessage('error', '正在进行中的活动不可删除！');
			}else{
				showMessage('error', data['message']);
			}
		}
	})
}

//关闭正在进行的限时折扣
function closeTopic(topic_id){
	$.ajax({
		type:"post",
		url : "{:__URL('PLATFORM_MAIN/promotion/closeTopic')}",
		data : { "topic_id" : topic_id },
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/promotion/topicList')}");
			}else{
				showMessage('error', data["message"]);
			}
		}
	})
}
function topicInfo(topic_id){
	$("#topicInfo").modal("show");
	$.ajax({
		type:"get",
		url : "{:__URL('PLATFORM_MAIN/promotion/getTopicDetail')}",
		data : { "topic_id" : topic_id },
		success : function(data) {
			$("#topic_name").text(data["topic_name"]);
			$("#keyword").text(data["keyword"]);
			$("#desc").text(data["desc"]);
			$("#picture_img").attr("src",__IMG(data['picture_img']));
			$("#scroll_img").attr("src",__IMG(data['scroll_img']));
			$("#background_img").attr("src",__IMG(data['background_img']));
			$("#time").text(timeStampTurnTime(data['start_time'])+' 至 '+timeStampTurnTime(data['end_time']));
			switch(data['status']){
					case 0:
						var status_name = '未发布';
						break;
					case 1:
						var status_name = '进行中';
						break;
					case 3:
						var status_name = '关闭';
						break;
					case 4:
						var status_name = '结束';
						break;
			}
			$("#status").text(status_name);
			var goods_list = '';
			for(var i=0;i<data['goods_list'].length;i++){
				goods_list += '<tr>';
				goods_list += '<td><a class="img-container" href="javascript:;"><img src="'+__IMG(data['goods_list'][i]['picture_info']['pic_cover_micro'])+'"></a></td>';
				goods_list += '<td>'+data['goods_list'][i]['goods_name']+'</td>';
				goods_list += '</tr>';
			}
			$("#discountInfo table tr:gt(4)").remove();
			$("#goods_list").after(goods_list);
		}
	})
}

//全选
function CheckAll(event){
	var checked = event.checked;
	if(checked) $(".table-class tbody input[type = 'checkbox'][name='sub_no_use']").prop("checked",checked).parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox'][name='sub_no_use']").prop("checked",checked).parent().removeClass("selected");
}

//批量删除
function batchDelete() {
	var topic_id = new Array();
	$(".table-class tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			topic_id.push($(this).val());
		}
	});

	if(topic_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	delTopic(topic_id);
}
</script>
{/block}